package com.zhazha.earlybird;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zhazha.earlybird.JobHelpActivity.MyButtonListener;
import com.zhazha.earlybird.control.CommonControl;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class JobHelpShowActivity extends Activity {
	
	ListView InfolistView=null;
	
    String title=null;
    ArrayList<String> title_list=null;
    
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
	     setContentView(R.layout.jobhelp_list);
	     
	
	     
	     InfolistView =(ListView)findViewById(R.id.jobhelp_list_listview_info);
	     
	     
	     
	 
	     Bundle extras=getIntent().getExtras();
	     if(extras!=null)
	     {
	    	 title=extras.getString("title");
	    	 TextView tv=(TextView)findViewById(R.id.jobhelp_list_textview_logo);
	    	 tv.setText(title);
	    	 //Init_list();
	    	 CommonControl comCtrl = CommonControl.getInstance();
		     
		     comCtrl.getSqlCtrl().setContext(this);
		     title_list=comCtrl.getSqlCtrl().gettitle(title);
	     }
	     
	     InfolistView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
	     SimpleAdapter Infoadapter = new SimpleAdapter(this,getData(),R.layout.moreoperation_list_item,
	                new String[]{"title","img"},
	                new int[]{R.id.moreoperation_list_item_textview,R.id.moreoperation_list_item_imageview});
	     InfolistView.setAdapter(Infoadapter);
	   
	     InfolistView.setOnItemClickListener(new MyButtonListener());
	}
	
	
	
	private List<Map<String, Object>> getData()
	 {
		 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		 Map<String, Object> map = null;
		 
		 for(int i=0;i<title_list.size();i++)
		 {
			 
			map = new HashMap<String, Object>();
	        map.put("title", title_list.get(i));
	        map.put("img", R.drawable.retrive_list_arrow);
	        list.add(map);
		 }
		
	   
	         
	        return list;
	 }
	
	class MyButtonListener implements  AdapterView.OnItemClickListener
	{

		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			Intent next_intent=new Intent(JobHelpShowActivity.this,ArticleDetailActivity.class);
			HashMap<String,String> map=(HashMap<String,String>)InfolistView.getItemAtPosition(arg2); 
            String title=map.get("title"); 
            next_intent.putExtra("title", title);
            JobHelpShowActivity.this.startActivity(next_intent);
          
		}
		
		
	}
}
